package com.kintreda.ieco_server.module.account.web;

import com.kintreda.ieco_server.util.image.Image;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;

/**
 * 初始化控制层
 * @author HuangZhongYao
 *
 */
@Controller
public class InitController {

	
	@RequestMapping("/")
	public ModelAndView index() {
		
		ModelAndView mv = new ModelAndView("login");

	
		return mv;
		
	}

	/*********************************************
	 * 获取验证码
	 *
	 * @param request
	 * @param response
	 */
	@RequestMapping("/checkcode")
	public void checkcode(HttpServletRequest request,
						  HttpServletResponse response) {
		try {
			response.setHeader("Pragma", "no-cache");
			response.setDateHeader("Expires", 1L);
			response.setHeader("Cache-Control", "no-cache");
			response.addHeader("Cache-Control", "no-store");
			response.setContentType("image/jpeg");
			BufferedImage image = Image.creatImage(request.getSession());
			ImageIO.write(image, "JPEG", response.getOutputStream());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
